﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using libZPlay;
using System.Threading;
namespace information
{
    public partial class Audio : Form
    {
        public Audio()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {

            Thread oThread = new Thread(new ThreadStart(ProcessShow));//创建线程,用于音频的处理
            oThread.Start(); //开始线程
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            OpenFileDialog open = new OpenFileDialog();//创建打开文件对话框对象
            if (open.ShowDialog() == DialogResult.OK) //执行ShowDialog方法，返回OK，没有选定则无返回，则其他界面是假死状态
            {
                this.textBox1.Text = open.FileName.ToString();//获取文件 value.Tostring 返回为string
            }
        }

        //这里，就是后台进程开始工作时，调用工作函数的地方。
        public void ProcessShow()
        {
            ZPlay player = new ZPlay();  //建立播放对象
            player.OpenFile(textBox1.Text, TStreamFormat.sfAutodetect);  //传递音乐文件路径
            ///获取音乐时间长度
            TStreamInfo iMusicTime = new TStreamInfo();
            player.GetStreamInfo(ref iMusicTime);
            label1.Text = String.Format("{0:D1}:{1:D2}", iMusicTime.Length.hms.minute, iMusicTime.Length.hms.second);
            player.StartPlayback();  //开始播放
        }

        private void Audio_Load(object sender, EventArgs e)
        {
            label1.Text = "";
        }
    }
}
